package com.jacky.thread;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

/**
 * Created by Administrator
 */
public class MyWorkThread extends Thread {
    private AtomicInteger atomicInteger;

    public MyWorkThread(AtomicInteger atomicInteger, Runnable runnable) {
        super(runnable);
        this.atomicInteger = atomicInteger;
    }


    @Override
    public void run() {
        System.out.println(this.getName() + " test" + atomicInteger.getAndDecrement());
        super.run();
    }

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        // 获取对应的平方数
        List<Integer> squaresList = numbers.stream().map(i -> i * i).distinct().collect(toList());
        System.out.println(squaresList);

        List<Integer> list = (List<Integer>) Stream.of(Arrays.asList(1, 2, 3, 4, 5, 6), Arrays.asList(8, 9, 10, 11, 12))
                .flatMap(test -> test.stream()).collect(toList());
        /**
         map和flatmap的区别
         map只是一维 1对1 的映射
         而flatmap可以将一个2维的集合映射成一个一维,相当于他映射的深度比map深了一层 ,
         所以名称上就把map加了个flat 叫flatmap*/
        String[] words = new String[]{"Hello", "World"};
        List<String[]> a = Arrays.stream(words)
                .map(word -> word.split(""))
                .distinct()
                .collect(toList());
        a.forEach(System.out::print);

        List<String> b = Arrays.stream(words)
                .map(word -> word.split(""))
                .flatMap(Arrays::stream)
                .distinct()
                .collect(toList());
        b.forEach(System.out::print);
    }


}